package sgd.tp2.server.net;

import sgd.tp2.api.net.NetProtocolType;
import sgd.tp2.server.cmdline.ConfigurationOptions;
import sgd.tp2.server.net.tcp.TCPServerBytes;
import sgd.tp2.server.net.tcp.TCPServerCSV;
import sgd.tp2.server.net.tcp.TCPServerJSON;
import sgd.tp2.server.net.tcp.TCPServerObject;
import sgd.tp2.server.net.tcp.TCPServerXML;
import sgd.tp2.server.net.udp.UDPServerBytes;
import sgd.tp2.server.net.udp.UDPServerCSV;
import sgd.tp2.server.net.udp.UDPServerJSON;
import sgd.tp2.server.net.udp.UDPServerObject;
import sgd.tp2.server.net.udp.UDPServerXML;

public final class ServerFactory {

	public static Server getServerInstance(ConfigurationOptions options) {
		if (options.protocol == NetProtocolType.TCP) {
			switch (options.format) {
				default:
					return new TCPServerXML(options.format, options.port, options.cep);
				case JSON:
					return new TCPServerJSON(options.format, options.port, options.cep);
				case CSV:
					return new TCPServerCSV(options.format, options.port, options.cep);
				case OBJECT:
					return new TCPServerObject(options.format, options.port, options.cep);
				case BYTES:
					return new TCPServerBytes(options.format, options.port, options.cep);
			}
		} else {
			switch (options.format) {
				default:
					return new UDPServerXML(options.format, options.port, options.cep,
							options.packetSize);
				case JSON:
					return new UDPServerJSON(options.format, options.port, options.cep,
							options.packetSize);
				case CSV:
					return new UDPServerCSV(options.format, options.port, options.cep,
							options.packetSize);
				case OBJECT:
					return new UDPServerObject(options.format, options.port, options.cep,
							options.packetSize);
				case BYTES:
					return new UDPServerBytes(options.format, options.port, options.cep,
							options.packetSize);
			}
		}
	}
}
